#pragma once

#include <vector>
#include <fstream>
using namespace std;

#include "typedefs.h"
using namespace Math;

namespace TriReader
{
   bool OpenFile(const char* filename, ifstream& fin);

   bool ReadTriFile(const char* filename, Real*& vs, int*& fs, int& vn, int& fn);
   bool ReadParFile(const char* filename, Real*& vs, int*& fs, int& vn, int& fn);
   bool ReadTriFile(const char* filename, Real*& vs, int vn);

   bool ReadOffFile(const char* filename, Real*& vs, int*& fs, int& vn, int& fn);
   bool ReadOffFile(const char* filename, Real*& vs, int vn);

   //bool ReadObjFile(const char* filename, Real*& vs, int*& fs, int& vn, int& fn);
   bool ReadObjFile(const char* filename, Real*& vs, int*& fs, Real*& ts, int*& tis, int& vn, int& fn, int& tn);
   bool ReadObjFileNoUvCorrect(const char* filename, Real*& vs, int*& fs, Real*& ts, int*& tis, int& vn, int& fn, int& tn);
   
   bool ReadObjFile(const char* filename, Real*& vs, int vn);

   bool ReadSmfFile(const char* filename, Real*& vs, int*& fs, int& vn, int& fn);

    bool ReadObjFileSingleMesh(ifstream& ifile, int vert_offset, Real*& vs, int*& fs, int& vn, int& fn);
    void ParseObjHeader(ifstream& ifile);

   bool ReadDCMeshFile(const char* filename, Real*& vs, int*& fs, int& vn, int& fn);

   bool ReadPairsFile(const char* filename, int*& ids, int& n);


   /**
        This method corrects texturated meshes getting one texture coordinate
        per vertex.
        Basically, duplicates vertices which have many texture coordinates.
   */
   void correct_uv_coordinates(vector<double> &pos, 
                               vector<double> &normal,
                               vector<double> &tex,
                               vector<int>    &posind,
                               vector<int>    &normalind,
                               vector<int>    &texind);
};

